package com.woniu.cq.medical.controller;


import com.woniu.cq.medical.common.PageResult;
import com.woniu.cq.medical.common.Result;
import com.woniu.cq.medical.entity.Patient;
import com.woniu.cq.medical.service.IMedicalCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2020-09-05
 */
@RestController
@RequestMapping("/medical/medical-card")
@Slf4j
public class MedicalCardController {
    @Autowired
    private IMedicalCardService medicalCardService;

    @RequestMapping("selectMessage")
    public Result selectMessage(String card){
        log.info("传入的参数-身份证为：{}",card);
        Patient patient = medicalCardService.selectMessage(card);
        log.info("查询出的患者基本信息为：{}",patient);
        if(patient==null){
            return Result.fail("error","请先创建病人信息");
        }else {
            return Result.success(patient);
        }

    }

    @PostMapping("/insertCard")
    public Result insertCard(String patientId){
        log.info("传入的参数-病人为：{}",patientId);
        medicalCardService.insertCard(Integer.parseInt(patientId));
        return Result.success();
    }

    @PostMapping("/updateCard")
    public Result updateCard(String patientId){
        log.info("传入的参数-病人为：{}",patientId);
        medicalCardService.updateCard(Integer.parseInt(patientId));
        return Result.success();
    }

    @PostMapping("/deleteCard")
    public Result deleteCard(String patientId){
        log.info("传入的参数-病人为：{}",patientId);
        medicalCardService.deleteCard(Integer.parseInt(patientId));
        return Result.success();
    }

}

